package com.yxjx.duoxue.message;

import org.json.JSONException;
import org.json.JSONObject;

import com.yxjx.duoxue.datamodel.DMObject;
import com.yxjx.duoxue.utils.UIHelper;

public class ClientMessageDTS extends DMObject implements java.io.Serializable {

    private static final long serialVersionUID = 1L;

    private Integer id;
    // 消息类别,0系统消息,1用户消息
    private Integer messageType = 0;
    // (预留)发送类型,0静默,2消息
    private Integer sendType = 0;
    // 消息图标
    private String messageLogo = "";
    // 消息标题
    private String messageTitle = "";
    // (预留)消息摘要
    private String messageSummary = "";
    // 消息内容
    private String messageContent = "";
    // 消息内链,可以为app内链,可以为web地址
    private String messageUri = "";
    // (预留)消息是否已读,0未读消息,1已读消息
    private Integer messageRead = 0;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getMessageType() {
        return messageType;
    }

    public void setMessageType(Integer messageType) {
        this.messageType = messageType;
    }

    public Integer getSendType() {
        return sendType;
    }

    public void setSendType(Integer sendType) {
        this.sendType = sendType;
    }

    public String getMessageLogo() {
        return messageLogo;
    }

    public void setMessageLogo(String messageLogo) {
        this.messageLogo = messageLogo;
    }

    public String getMessageTitle() {
        return messageTitle;
    }

    public void setMessageTitle(String messageTitle) {
        this.messageTitle = messageTitle;
    }

    public String getMessageSummary() {
        return messageSummary;
    }

    public void setMessageSummary(String messageSummary) {
        this.messageSummary = messageSummary;
    }

    public String getMessageContent() {
        return messageContent;
    }

    public void setMessageContent(String messageContent) {
        this.messageContent = messageContent;
    }

    public String getMessageUri() {
        return messageUri;
    }

    public void setMessageUri(String messageUri) {
        this.messageUri = messageUri;
    }

    public Integer getMessageRead() {
        return messageRead;
    }

    public void setMessageRead(Integer messageRead) {
        this.messageRead = messageRead;
    }

    @Override
    public String toString() {
        return "{\"id\":\"" + id + "\", \"messageType\":\"" + messageType + "\", \"sendType\":\"" + sendType + "\", \"messageLogo\":\"" + messageLogo
                + "\", \"messageTitle\":\"" + messageTitle + "\", \"messageSummary\":\"" + messageSummary + "\", \"messageContent\":\"" + messageContent
                + "\", \"messageUri\":\"" + messageUri + "\", \"messageRead\":\"" + messageRead + "\"}";
    }
    
    public static ClientMessageDTS from(String str) {
    	if (UIHelper.isEmpty(str)) {
    		return null;
    	}
    	
    	try {
			JSONObject jo = new JSONObject(str);
			ClientMessageDTS item = new ClientMessageDTS();
			item.setId(castInteger(jo,"id"));
			item.setMessageContent(castString(jo,"messageContent"));
			item.setMessageLogo(castString(jo,"messageLogo"));
			item.setMessageSummary(castString(jo,"messageSummary"));
			item.setMessageTitle(castString(jo,"messageTitle"));
			item.setMessageRead(castInteger(jo,"messageRead"));
			item.setMessageType(castInteger(jo,"messageType"));
			item.setMessageUri(castString(jo,"messageUri"));
			item.setSendType(castInteger(jo,"sendType"));
			return item;
		} catch (JSONException e) {
			e.printStackTrace();
		}
    	return null;
    	
    }
}